/*
* Single Window Application Template:
* A basic starting point for your application.  Mostly a blank canvas.
*
* In app.js, we generally take care of a few things:
* - Bootstrap the application with any data we need
* - Check for dependencies like device type, platform version or network connection
* - Require and open our top-level UI component
*
*/

/*
 * mobilesdk/...builder.py --> Oliver
 */

//bootstrap and check dependencies
if (Ti.version < 1.8) {
	alert('Sorry - this application template requires Titanium Mobile SDK 1.8 or later');
}

//var geomodule = require('de.geomodule');

// This is a single context application with mutliple windows in a stack
(function() {
	//determine platform and form factor and render approproate components
	var osname = Ti.Platform.osname, version = Ti.Platform.version, height = Ti.Platform.displayCaps.platformHeight, width = Ti.Platform.displayCaps.platformWidth;

	//considering tablet to have one dimension over 900px - this is imperfect, so you should feel free to decide
	//yourself what you consider a tablet form factor for android
	var isTablet = osname === 'ipad' || (osname === 'android' && (width > 899 || height > 899));

	var Window;
	if (isTablet) {
		Window = require('ui/tablet/ApplicationWindow');
	} else {
		// Android uses platform-specific properties to create windows.
		// All other platforms follow a similar UI pattern.
		if (osname === 'android') {
			Window = require('ui/handheld/android/ApplicationWindow');
		} else {
			Window = require('ui/handheld/ApplicationWindow');
		}
	}
	//var win = new Window();

	var win = Ti.UI.createWindow();

	win.setBackgroundColor('#abffff');

	var button = Titanium.UI.createButton({
		title : 'olik122',
		top : 10,
		width : 100,
		height : 50
	});

	var delta = 0.01;

	// Ti.include('anno.js');

	//var httpCaller= new WSCALLER('http://173.194.66.141/getnxtab?hs=559557&time=1344454853607');

	

	var WSCALLER = require('WSCaller');
    var WSMAP = require('WSMap');
	var KOORDINATE = require ('Koordinate');
	
	Ti.API.info(KOORDINATE.Distance(47.731016,9.253851 , 47.731016, 8.253851 ));
	    
	// (pURL, pHalteStelleType, pHalteStelleTitle, pHalteStelleDistanceM)

	LinienTyp_BUS = 1 << 1;
	LinienTyp_SBAHN = 1 << 2;
	LinienTyp_UBAHN = 1 << 3;
	LinienTyp_ZAHNRAD = 1 << 4;

	HalteStelleType = LinienTyp_SBAHN | LinienTyp_UBAHN;
	
	//var time = new Date().getTime();
	
	//var httpCaller = new WSCALLER(annotations, 'http://geolessiprovider.appspot.com/getnxtab?hs=559557&time='+time, HalteStelleType, '2', '999');

    //var wsMap = new WSMAP("MainWinMap", win);

	//var httpCaller= new WSCALLER('http://173.194.66.141/getnxtab?hs=559557&time=1344454853607');


	var testANNO = false;


	if(testANNO)
	{
	//win.add(mapview);
	//win.add(httpCaller.getView());
	
	var annotation = Ti.Map.createAnnotation({
		latitude : 37.38,
		longitude : -122.0502,
		animate : true,
		pincolor : Ti.Map.ANNOTATION_RED,
	});
	
	//var httpCaller = new WSCALLER(annotation, [562247,562248], HalteStelleType, 'Schlossplatz, Stuttgart', '123');
	var httpCaller = new WSCALLER(annotation, [558679], LinienTyp_BUS, 'Schlossplatz, Stuttgart', '123');
	
	httpCaller.create();
	
	win.add(annotation.getLeftView());

	}else
	{
		    var wsMap = new WSMAP("MainWinMap", win);

	win.add(wsMap.getView());
	wsMap.createButtons(win);	
	win.setNavBarHidden(true);
	}	
	
	
	
	
	
	
	
	
	
	
	//win.add(button);
	win.open();
	

})();
